package com.c.ctgproject.adapter.guang

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.LinearLayout
import android.widget.RelativeLayout
import android.widget.TextView
import androidx.appcompat.widget.LinearLayoutCompat
import androidx.recyclerview.widget.RecyclerView
import com.c.ctgproject.R
import com.c.ctgproject.base.BaseEmptyRecyclerViewAdapterV2
import com.c.ctgproject.entity.guang.BatteryInWarehouseEntity
import com.c.ctgproject.entity.guang.BatteryInpuOtherEntity
import com.c.ctgproject.entity.guang.CarListEntity
import com.c.ctgproject.entity.guang.PowerBatteryOutEntity
import com.c.ctgproject.ui.collect.*
import com.c.ctgproject.utils.MyConstants
import com.c.ctgproject.utils.getGson
import com.c.ctgproject.utils.handlerNull
import com.c.ctgproject.utils.noDataHandler
import org.jetbrains.anko.startActivity
import org.jetbrains.anko.textColorResource

class BatteryInputOtherAdapter(private val context: Context, private val mList: List<BatteryInpuOtherEntity.DataBean.ListBean>,private val listener:BatteryInputOtherCallBack) : BaseEmptyRecyclerViewAdapterV2(context, mList) {
    override fun createViewHolder(parent: ViewGroup): RecyclerView.ViewHolder {
        val view = LayoutInflater.from(context).inflate(R.layout.item_battery_input_other_list, parent, false)
        return MyViewHolder(view)
    }

    override fun handlerData(holder: RecyclerView.ViewHolder, position: Int) {
        if (holder is MyViewHolder) {
            val ac=context as BatteryInputOtherActivity
            holder.mBottomRL.visibility=if (ac.searchMine) View.GONE else View.VISIBLE

            val data = mList[position]
//            holder.carPlate.text = data.carPlate.noDataHandler()
            holder.batteryName.text = data.batteryName.noDataHandler()
            holder.batteryCode.text = data.batteryCode.noDataHandler()
            holder.batterySelfCode.text = data.batterySelfCode.noDataHandler()
            holder.bulkInOrderNo.text=data.bulkInOrderNo.noDataHandler()
//            holder.count.text = data.count.noDataHandler()
            holder.capacityAh.text = data.capacityAh.noDataHandler()
            holder.capacityKwh.text = data.capacityKwh.noDataHandler()
            holder.voltage.text = data.voltage.noDataHandler()
            val batteryType = when (data.batteryType) {
                1 -> "电池包"
                2 -> "模组"
                3 -> "电芯"
                else -> "暂无数据"
            }
            holder.batteryType.text = batteryType

            holder.mBottomRL.setOnClickListener {
                holder.mBTN.performClick()
            }
            holder.mBTN.setOnClickListener {
                //补充信息
                context.startActivity<BatteryInputOtherActivityDetailActivity>(MyConstants.DATA to data)
            }
            holder.mParentLL.setOnClickListener {
                //入库单详情
                context.startActivity<BatteryCanHandlerDetailActivity>(MyConstants.ID to data.pbId)
//                context.startActivity<BatteryDetailActivity>(MyConstants.ORDER_ID to data.orderId)
            }
            //holder.mDeleteBTN.visibility=if(data.isRemove==1)View.VISIBLE else View.GONE
            holder.mDeleteBTN.visibility=View.GONE
            holder.mDeleteBTN.setOnClickListener {
                listener.itemDelete(position,data)
            }
        }
    }
    interface BatteryInputOtherCallBack{
        fun itemDelete(position: Int,data:BatteryInpuOtherEntity.DataBean.ListBean)
    }
    inner class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) {
//        val carPlate: TextView = view.findViewById(R.id.carPlate)
        val batteryName: TextView = view.findViewById(R.id.batteryName)
        val batteryCode: TextView = view.findViewById(R.id.batteryCode)
        val batterySelfCode: TextView = view.findViewById(R.id.batterySelfCode)
//        val count: TextView = view.findViewById(R.id.count)
        val batteryType: TextView = view.findViewById(R.id.batteryType)

        val capacityAh: TextView = view.findViewById(R.id.capacityAh)
        val capacityKwh: TextView = view.findViewById(R.id.capacityKwh)
        val voltage: TextView = view.findViewById(R.id.voltage)
        val mBottomRL: RelativeLayout = view.findViewById(R.id.mBottomRL)
        val mBTN: Button = view.findViewById(R.id.mBTN)
        val mParentLL: LinearLayout = view.findViewById(R.id.mParentLL)
        val mDeleteBTN:Button=view.findViewById(R.id.mDeleteBTN)
        val bulkInOrderNo: TextView = view.findViewById(R.id.bulkInOrderNo)
    }


}